<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row bt">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                            <i class="fa  fa-fw fa-reorder"></i>修改直播信息
                        </li>
                    </ol>
                </div>
            </div>
            <div id="page-wrapper">
                <div class="container-fluid col-md-7 col-sx-12">
                    <form action="/admin_guide/edit" method="post" enctype="multipart/form-data">
                        <div class="form-group ">
                            <label for="title">指南标题</label>
                            <input type="text" placeholder="指南标题" id="title" class="form-control" name="title" value="<?=$tRow['title']?>">
                        </div>
                        <div class="form-group">
                            <label for="cate_id">文献类别</label>
                            <select class="form-control" id="cate_id" name="cate_id">
                                <option value="">=请选择=</option>
                                <?foreach($tType as $tTRow){?>
                                <option value="<?=$tTRow['id']?>" <?if($tRow['cate_id'] == $tTRow['id']){echo 'selected';}?>><?=$tTRow['name']?></option>
                                <?}?>
                            </select>
                        </div>
                        <div class="form-group <?if(empty($tRow['tag'])){echo "hidden";}?>">
                            <label for="tag">标签</label>
                            <select class="form-control" id="tag" name="tag">
                                <option value="">=请选择=</option>
                                <option value="血液透析" <?if($tRow['tag'] == "血液透析"){echo 'selected';}?>>血液透析</option>
                                <option value="腹膜透析" <?if($tRow['tag'] == "腹膜透析"){echo 'selected';}?>>腹膜透析</option>
                                <option value="肾脏移植" <?if($tRow['tag'] == "肾脏移植"){echo 'selected';}?>>肾脏移植</option>
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="img_new">指南封面图片(宽190x高164)</label>
                            <input type="hidden"  id="img_new" class="form-control" name="img_new" value='<?=$tRow['img']?>'>
                            <input type="file" id="file_input" name="img">
                        </div>
                        <div class="form-group">
                            <label for="source">来源</label>
                            <input type="text" placeholder="来源" id="source" class="form-control" name="source" value='<?=$tRow['source']?>'>
                        </div>
                        <div class="form-group">
                            <label for="keywords">关键字(请输入以逗号隔开的格式)</label>
                            <input type="text" placeholder="关键字" id="keywords" class="form-control" name="keywords" value='<?=$tRow['keywords']?>'>
                        </div>
                        <div class="form-group">
                            <label for="descriptions">指南摘要</label>
                            <textarea id="descriptions" style="height:200px;resize:none;" class="form-control" name="descriptions" placeholder="指南摘要"><?=$tRow['descriptions']?></textarea>
                        </div>
                        <div class="form-group">
                            <label for="content">指南内容</label>
                            <!-- 加载编辑器的容器 -->
                            <script id="container" name="content" type="text/plain"><?=htmlspecialchars_decode($tRow['content'])?></script>
                        </div>
                        <div class="form-group ">
                            <label for="recommend">是否推荐&nbsp;&nbsp;</label>
                            <input type="radio" name="recommend" value="0" <?=empty($tRow['recommend'])?"checked":""?>>&nbsp;&nbsp;不推荐&nbsp;&nbsp;
                            <input type="radio" name="recommend" value="1" <?=empty($tRow['recommend'])?"":"checked"?>>&nbsp;&nbsp;推荐&nbsp;&nbsp;
                        </div>

                       <input type='hidden' value='<?=$tId?>' name='id'/>
                        <button class="btn btn-primary demo_2" type="button" id="submit">修改</button>
                    </form>
                </div>
                <div class="container-fluid col-md-5">
                    <div class="images text-center" id="img_view">
                <?if(!empty($tRow['img'])){?><img src='<?=$tRow['img']?>' width='400px' /><?}?>
                    </div>
                </div>
            </div>
        </div>
        <div class="subviews">
            <div class="subviews-container"></div>
        </div>
    </div>
    <!-- end: PAGE -->
</div>
<!-- end: MAIN CONTAINER -->
<!-- 配置文件 -->
<script type="text/javascript" src="/plugins/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/plugins/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container',{
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline','fontborder', 'strikethrough', '|','simpleupload', 'insertimage','attachment','emotion','link','unlink', '|', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote','searchreplace', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc'],
            ['inserttable','insertrow', 'insertcol','mergeright', 'mergedown','deleterow', 'deletecol','splittorows','splittocols', 'splittocells','deletecaption','inserttitle', 'mergecells', 'deletetable','insertparagraphbeforetable', 'paragraph','fontsize','fontfamily']
        ],
        initialFrameHeight:260,
        zIndex:1000
    });
</script>
<script>
$(function(){
    $('#cate_id').change(function(){
        if($('#cate_id').find('option:selected').text() == '肾脏替代'){
            //$('#tag').parent().attr('class','form-group');
            $('#tag').parent().removeClass('hidden');
        }else{
            $('#tag').parent().addClass('hidden');
            $('#tag').val('');
        }
    });
});
</script>

<script>
$(function(){
    var options={
        beforeSubmit : showRequest,    // 提交前的回调函数
        success : showResponse,    // 提交后的回调函数
        dataType : "json",    // html（默认）、xml、script、json接受服务器端返回的类型
    }
    function showRequest(formData, jqForm, options){
        return true;
    }
    function showResponse(responseText,statusText){
            cg_alert_edit(responseText,'/admin_guide','/admin_guide/edit?id=<?=$tId?>');
    }
    $('#submit').click(function() {
        $('form').ajaxSubmit(options);
        return false;

    });
});

var result = document.getElementById("img_view");
var input = document.getElementById("file_input");

if(typeof FileReader==='undefined'){
   result.innerHTML = "抱歉，你的浏览器不支持 FileReader";
   input.setAttribute('disabled','disabled');
}else{
   input.addEventListener('change',readFile,false);
}
function readFile(){
   var file = this.files[0];
   if(!/image\/\w+/.test(file.type)){
       alert("文件必须为图片！");
       return false;
   }
   var reader = new FileReader();
   reader.readAsDataURL(file);
   reader.onload = function(e){
       result.innerHTML = '<img src="'+this.result+'" alt="" width="400px"/>'
   }
}
</script>
<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
